package com.app.service.impl;

import com.app.common.EducationTool;
import com.app.mapper.CusEducationMapper;
import com.app.mapper.CusItemExpMapper;
import com.app.model.*;
import com.app.service.CusEducationService;
import com.app.service.CusItemExpService;
import com.app.service.CustomerService;
import com.app.service.UserService;
import com.app.util.CommonHelp;
import com.app.util.Result;
import com.app.util.TokenUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;


/**
 * @Description:项目经验
 */
@Service
public class CusItemExpServiceImpl implements CusItemExpService {
    @Autowired
    UserService userService;
    @Autowired
    CustomerService customerService;
    @Autowired
    CusItemExpService cusItemExpService;
    @Autowired
    CusItemExpMapper cusItemExpMapper;

    @Override
    public int insert(CusItemExpModel model) {
        return cusItemExpMapper.insert(model);
    }

    @Override
    public void update(CusItemExpModel model) {
        cusItemExpMapper.updateById(model);
    }

    @Override
    public List<CusItemExpModel> getItemExpByCustomerId(int customerId) {
        QueryWrapper<CusItemExpModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.select().eq("customer_id",customerId);
        List<CusItemExpModel> userList = cusItemExpMapper.selectList(queryWrapper);
        if(userList.isEmpty())
        {
            return null;
        }else {
            return userList;
        }
    }


    @Override
    public void delete(int id) {
        cusItemExpMapper.deleteById(id);
    }

    @Override
    //根据简历ID查询教育经历
    public Object getItemExpList(int customerId) {
        QueryWrapper<CusItemExpModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.select().eq("customer_id",customerId);
        List<CusItemExpModel> CusItemExpList = cusItemExpMapper.selectList(queryWrapper);
        if(CusItemExpList.isEmpty())
        {
            return null;
        }else {
            return CusItemExpList;
        }
    }

    @Override
    //根据ID查询教育经历
    public Object getItemExp(HttpServletRequest request) {
        JSONObject json = new JSONObject();
        String id = request.getParameter("id");
        CusItemExpModel model = cusItemExpMapper.selectById(Integer.valueOf(id));
        if(model!=null)
        {
            List<CusItemExpModel> modelList = new ArrayList<>();
            modelList.add(model);
            return modelList.get(0);
        }
        return null;
    }

}
